abstract class Cake {
    private String name;

    public Cake(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public abstract double getPrice();
}

class Pancake extends Cake {
    public Pancake() {
        super("手抓饼");
    }

    public double getPrice() {
        return 6.0;
    }
}

abstract class Condiment extends Cake {
    protected Cake cake;

    public Condiment(String name, Cake cake) {
        super(name);
        this.cake = cake;
    }

    public String getName() {
        return cake.getName() + " 加" + super.getName();
    }
}

class Lettuce extends Condiment {
    public Lettuce(Cake cake) {
        super("生菜", cake);
    }

    public double getPrice() {
        return cake.getPrice() + 1;
    }
}

class Bacon extends Condiment {
    public Bacon(Cake cake) {
        super("培根", cake);
    }

    public double getPrice() {
        return cake.getPrice() + 3;
    }
}

class Ham extends Condiment {
    public Ham(Cake cake) {
        super("火腿", cake);
    }

    public double getPrice() {
        return cake.getPrice() + 2;
    }
}

class Egg extends Condiment {
    public Egg(Cake cake) {
        super("鸡蛋", cake);
    }

    public double getPrice() {
        return cake.getPrice() + 1.5;
    }
}

public class DecoratorTest {

    static public void out(Cake c) {
        System.out.printf("%s%2c%10.2f元\n",
                            c.getName(), ' ', c.getPrice());
    }

    static public void main(String [] args) {
        Cake cake = new Pancake();

        out(cake);
        out(new Lettuce(cake));
        out(new Ham(cake));
        out(new Egg(cake));
        out(new Bacon(cake));
        System.out.printf("======================\n");
        out(new Egg(new Lettuce(new Ham(new Egg(new Bacon(cake))))));

        Egg e = new Egg(cake);
        for (int i = 1; i < 10; ++i) {
            e = new Egg(e);
        }
        out(e);
    }
}
